<?php

defined( 'PDNS_CORE' ) or die( "Unauthorized" );

class Request{
	/**
	 *  Adds/sets a new variable to the request array
	 *
	 *  @param string name of variable
	 *  @param string value
	 */
	public static function set( $name, $value ){
		$_REQUEST[$name] = $value;
	}

	public static function get( $name, $default='', &$array=null, $filter='word' ){
		if( ! $array )
			$array =& $_REQUEST;
		
		if( ! isset( $array[$name] ))
			return $default;
		
		$value = $array[$name];

		switch( $filter ){
			case 'domain':
				return preg_replace( '#[^.\-a-zA-Z0-9]#', '', $value );
			break;
			case 'int':
				return (int)$value;
			break;
			case 'none':
				return $value;
			break;
			case 'password':
				return $value;
			break;
			case 'word':
				return preg_replace( '#\W#', '', $value );
			break;
		}
	}
	
	public static function getDomain( $name, $default='', &$array=null ){
		return Request::get( $name, $default, $array, 'domain' );
	}
	
	public static function getInt( $name, $default='', &$array=null ){
		return Request::get( $name, $default, $array, 'int' );
	}
	
	public static function getPassword( $name, $default='', &$array=null ){
		return Request::get( $name, $default, $array, 'password' );
	}

	public static function getValue( $name, $default='', &$array=null ){
		return Request::get( $name, $default, $array, 'none' );
	}

	public static function getWord( $name, $default='', &$array=null ){
		return Request::get( $name, $default, $array, 'word' );
	}
}
